<?php
  if (!defined('EXPONENT')) exit('');
  if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate"),$loc))
  {   
      exponent_flow_set(SYS_FLOW_PROTECTED,SYS_FLOW_ACTION);
      
      // page title
      global $db;
      $title = $temp->title;
      
      require_once(BASE."modules/formhelpermodule/formhelper.php");

      $formhelper=new formhelper("administrationmodule","","_manager_users",$loc);
        $formhelper->setGridType(FORMHELPER_GRID_TYPE_DATAGRID);
        $formhelper->setGridOptions("height",705);
        $formhelper->setGridOptions("idField","id");
        $formhelper->setGridOptions("pagination",1);
        $formhelper->setGridOptions("pageNumber","1");
        $formhelper->setGridOptions("pageSize","20");
        $formhelper->setGridOptions("rownumbers","true");
        $formhelper->setGridOptions("nowrap","false");
        $formhelper->setGridOptions("singleSelect","true");
        $formhelper->setGridOptions("autoRowHeight","true");
        
        $formhelper->setGridID("manage_users");
        $js=URL_FULL."modules/administrationmodule/js/Manager_users.js";
        $formhelper->addJS($js);
        
        $formhelper->setColumnType(1);
        $formhelper->addColumn(array("field"=>"firstname","title"=>"First Name",'width'=>70));
        $formhelper->addColumn(array("field"=>"lastname","title"=>"Last Name",'width'=>70));
        $formhelper->addColumn(array("field"=>"username","title"=>"Username",'width'=>190));
        $formhelper->addColumn(array("field"=>"email","title"=>"Email",'width'=>190, "sortable"=>true));
        $formhelper->addColumn(array("field"=>"created_on","title"=>"Create on",'width'=>130, "sortable"=>true));
        $formhelper->addColumn(array("field"=>"last_login","title"=>"Last login",'width'=>130, "sortable"=>true));
        $formhelper->addColumn(array("field"=>"is_locked","title"=>"Locked",'width'=>50, "sortable"=>true,"formatter"=> 'function(value,row,index){if (value==0) return "No";else return "<b style=\"color:red\">Locked</b>"}'));
        $formhelper->addColumn(array("field"=>"is_acting_admin","title"=>"Role",'width'=>50, "sortable"=>true,"formatter"=> 'function(value,row,index){if (row.is_admin == 1) return "Super Admin"; else if (row.is_acting_admin ==1) return "Admin"; else return "Normal User"}'));
        $link_param="/index.php?module=administrationmodule&action=user_manage_json&src={$loc->src}&ajax_action=1";
        $formhelper->setURLDataStream($link_param);
        $formhelper->setGridOptions("onBeforeLoad","function(___form_onBeforeLoad");
        $formhelper->setGridOptions("onClickRow","function(___form_onClickRow");
        $toolbar_template=new template("administrationmodule","_manage_users_tool",$loc);
        $toolbar_template->assign('title',"Manage ".$title);
        $toolbar_template->register_permissions(array('administrate',"configure"),$loc);
        $toolbar_html=$toolbar_template->render();
        $formhelper->addToolbarHTML($toolbar_html);
        $formhelper->setPreInitJSCall("form_syslog_preinit");
        $formhelper->register_permissions(array('administrate',"configure"),$loc);
        $formhelper->output();       
  }
  else
    {
        echo exponent_http_error(403);
    }
?>

